package GuLi_Java;

public class Test01 {
    // 英雄类
    static class Hero {
        private String name;
        private Integer experience; // 经验 相比int而言Integer的默认值为null，整数与null.


        private Integer lever; // 等级
        private Integer attack; // 攻击力

        public Hero(String name) {// 新建英雄构造方法

            this.name = name;
            this.experience = 0; // 初始经验
            this.lever = 1; // 初始等级
            this.attack = 250; // 初始攻击力

        }


        // 获取英雄名字的方法
        public String getName() {
            return name;
        }

        // 改变英雄名字的方法
        public void setName(String name) {
            this.name = name;
        }

        public Integer getExperience() {
            return experience;
        }

        public void setExperience(Integer experience) {
            this.experience = experience;
        }

        public Integer getLever() {
            return lever;
        }

        public void setLever(Integer lever) {
            this.lever = lever;
        }

        public Integer getAttack() {
            return attack;
        }

        public void setAttack(Integer attack) {
            this.attack = attack;
        }

        public void AttackMonster(Monster monster) { //攻击怪物
            System.out.println("英雄" + this.name + "  攻击怪物  " + monster.getName() + "  造成了" + this.attack + "  伤害");
            // 接受怪物被攻击前血量
            Integer hp = monster.getHealthPoint(); //获取怪物的血量
            if (hp > this.attack) {
                // 判断如果怪物得的血量高于攻击力
                hp -= this.attack; //  怪物的血量减少攻击力的点数
            } else { // 反之攻击力高于怪兽血量，则怪兽直接死亡
                hp = 0;
            }
            // 改变怪兽被攻击后的血量
            monster.setHealthPoint(hp);
            System.out.println("怪物剩余血量：" + hp );

            // 经验设置
            if (hp == 0 && this.lever < 18) {
                System.out.println("英雄" + this.name + "的经验值增加" + monster.getExperience() + "点");
                // 更改英雄的经验点数
                this.experience = monster.getExperience() + this.experience;
                // 设定英雄升级条件
                if (this.experience >= lever * 100) {
                    this.experience = this.experience - lever * 100; // 经验值减去当前升级需要的经验值 溢出的进入下一个等级经验
                    this.lever += 1; // 等级加1
                    // 设定每升一级攻击力加25
                    this.attack += 25;
                    System.out.println("英雄" + this.name + "升级了,等级加1，攻击力+25，当前等级：" + this.lever + ",当前攻击力：" + this.attack);


                }
            }


        }

    }


    // 怪物类
    static class Monster {

        private String name; // 名字
        private Integer healthPoint; //血量
        private Integer lever; // 等级
        private Integer experience; // 经验


        public Monster(String name, Integer lever) {
            this.name = name;
            this.lever = lever; // 初始等级
            this.healthPoint = lever * 1000; // 初始经验
            this.experience = lever * 10; // 初始经验
        }


        // 获取怪物名字
        public String getName() {
            return name;
        }

        // 改变
        public void setName(String name) {
            this.name = name;
        }

        public Integer getHealthPoint() {
            return healthPoint;
        }

        public void setHealthPoint(Integer experience) {
            this.healthPoint = experience;
        }

        public Integer getLever() {
            return lever;
        }

        public void setLever(Integer lever) {
            this.lever = lever;
        }

        public Integer getExperience() {
            return experience;
        }

        public void setExperience(Integer attack) {
            this.experience = attack;
        }


    }

    public static void main(String[] args) throws Exception {
        Hero h = new Hero("蒋付杨"); //新建一个英雄
        Monster m = new Monster("蒋付杨心魔", 10);

        do {
            h.AttackMonster(m); // 攻击怪物

        } while (m.getHealthPoint() != 0); // 如果怪物没死一直攻击


    }


}
